﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Data;

namespace DataAccess {
    /// <summary>
    /// Class for retreiving user login data
    /// </summary>
    public class UserLogin_Access {

        /// <summary>
        /// User_s the login.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns>
        /// true if the user login data match, false otherwise
        /// </returns>
        public bool User_Login(UserLogin_Data obj) {
            string username = String.Empty;
            string password = String.Empty;
            CreateConnection objcon = new CreateConnection();
            try {
                string query = "SELECT username, password FROM Users" +
                " WHERE (username = '" + obj.UserName + "') AND (password = '" + obj.Password + "')";
                DataTable dt = objcon.CreateDataTable(query);
                username = dt.Rows[0]["username"].ToString();
                password = dt.Rows[0]["password"].ToString();
            } catch (Exception e) {
                Console.Write("Err msg:" + e.Message);
            }
            if (username.Equals(obj.UserName))
                return true;
            else
                return false;
        }
    }

    /// <summary>
    /// Class for retreiving admin login data
    /// </summary>
    public class AdminLogin_Access {
        /// <summary>
        /// User_s the login.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns>
        /// true if the user login data match, false otherwise
        /// </returns>
        public bool Admin_Login(AdminLogin_Data obj) {
            string username = String.Empty;
            string password = String.Empty;
            string client_id = string.Empty;
            CreateConnection objcon = new CreateConnection();
            try {
                string query = "SELECT username, password,client_id FROM Users" +
                " WHERE (username = '" + obj.UserName + "') AND (password = '" + obj.Password + "')";
                DataTable dt = objcon.CreateDataTable(query);
                username = dt.Rows[0]["username"].ToString();
                password = dt.Rows[0]["password"].ToString();
                client_id = dt.Rows[0]["client_id"].ToString();
                
            } catch (Exception e) {
                Console.Write("Err msg:" + e.Message);
            }
            if (username.Equals(obj.UserName)&&client_id.Equals("999"))
                return true;
            else
                return false;
        }
    }
}
